import type {CrudSchema} from '@/hooks/web/useCrudSchemas'
import {dateFormatter} from '@/utils/formatTime'

// 表单校验
export const rules = reactive({
  nickName: [required],
  avatar: [required],
  sign: [required],
  gender: [required],
  birthday: [required],
})

// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: '序号',
    field: 'index',
    type: 'index',
    isForm: false,
  },
  {
    label: '昵称',
    field: 'nickName',
    isSearch: true,
  },
  {
    label: '头像',
    field: 'avatar',
    isSearch: true,
  },
  {
    label: '个人签名',
    field: 'sign',
    isSearch: true,
  },
  {
    label: '性别',
    field: 'gender',
    isSearch: true,
    dictType: DICT_TYPE.VRS_USER_GENDER,
    search: {
      component: 'Select',
      componentProps: {
        style: 'width: 192px',
      }
    },
    form: {
      component: 'Select',
      componentProps: {
        style: 'width: 192px',
      },
    },
  },
  {
    label: '出生日期',
    field: 'birthday',
    isSearch: true,
    formatter: dateFormatter,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
        type: 'date',
      }
    }
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    isForm: false,
  },
  {
    label: '操作',
    field: 'action',
    isForm: false
  }
])
export const {allSchemas} = useCrudSchemas(crudSchemas)
